package com.hqj.controller;

import com.hqj.entity.QuestionBank;
import com.hqj.service.QuestionBankService;
import com.hqj.utils.Result;
import com.hqj.utils.ResultUtil;
import com.hqj.utils.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 黄啟军
 * @version 1.0
 * @date 2020/8/4 0004
 */
@Api(tags = "QuestionBankController")
@RestController
@RequestMapping("/questionBank")
@CrossOrigin
public class QuestionBankController {

    @Resource
    private QuestionBankService questionBankService;

    /***
     * 根据ID删除品牌数据
     * @param id
     * @return
     */
    @ApiOperation(value = "QuestionBank根据ID删除",notes = "根据ID删除QuestionBank方法详情",tags = {"QuestionBankController"})
    @DeleteMapping(value = "/{id}" )
    public ResultVO<String> delete(@PathVariable Long id){
        //调用QuestionBankService实现根据主键删除
        questionBankService.delete(id);
        return ResultUtil.success("删除成功");
    }

    /***
     * 修改QuestionBank数据
     * @param questionBank
     * @param id
     * @return
     */
    @ApiOperation(value = "QuestionBank根据ID修改",notes = "根据ID修改QuestionBank方法详情",tags = {"QuestionBankController"})
    @PutMapping(value="/{id}")
    public ResultVO<String> update(@RequestBody @ApiParam(name = "QuestionBank对象",value = "传入JSON数据",required = false) QuestionBank questionBank, @PathVariable Long id){
        //设置主键值
        questionBank.setId(id);
        //调用QuestionBankService实现修改QuestionBank
        questionBankService.update(questionBank);
        return ResultUtil.success("修改成功");
    }

    /***
     * 新增QuestionBank数据
     * @param questionBank
     * @return
     */
    @ApiOperation(value = "QuestionBank添加",notes = "添加QuestionBank方法详情",tags = {"QuestionBankController"})
    @PostMapping
    public ResultVO<String> add(@RequestBody  @ApiParam(name = "QuestionBank对象",value = "传入JSON数据",required = true) QuestionBank questionBank){
        //调用QuestionBankService实现添加QuestionBank
        questionBankService.add(questionBank);
        return ResultUtil.success("添加成功");
    }

    /***
     * 根据ID查询QuestionBank数据
     * @param id
     * @return
     */
    @ApiOperation(value = "QuestionBank根据ID查询",notes = "根据ID查询QuestionBank方法详情",tags = {"QuestionBankController"})
    @GetMapping("/{id}")
    public ResultVO<QuestionBank> findById(@PathVariable Long id){
        //调用QuestionBankService实现根据主键查询QuestionBank
        QuestionBank questionBank = questionBankService.findById(id);
        return ResultUtil.success(questionBank);
    }

    /***
     * 查询QuestionBank全部数据
     * @return
     */
    @ApiOperation(value = "查询所有QuestionBank",notes = "查询所QuestionBank有方法详情",tags = {"QuestionBankController"})
    @GetMapping
    public ResultVO<List<QuestionBank>> findAll(){
        //调用QuestionBankService实现查询所有QuestionBank
        List<QuestionBank> list = questionBankService.findAll();
        return ResultUtil.success(list);
    }
}
